package com.sample.springbatch.job.config;

import com.sample.springbatch.job.demo.config.BatchDemoConfig;
import com.sample.springbatch.job.sample.config.JobListenerConfig;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.support.ApplicationContextFactory;
import org.springframework.batch.core.configuration.support.GenericApplicationContextFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 作业加载到上下文中，让job的作业可以被加载到batch管理中
 *
 * Created by zwg on 2017/9/21.
 */
@Configuration
@EnableBatchProcessing(modular = true)
public class BatchJobLoadConfig {

    /**
     * 如果 BatchDemoConfig 中添加了Configuration注解，作业已经加载到了系统上下文中，但是不能被batch识别
     * 需要如下配置才能让batch识别到
     *
     * 方法名称  loadBatchDemoConfig 不能是作业名称   也不能拿是BatchDemoConfig名称，否则会覆盖或是加载识别
     *
     *
     * @return
     */
    @Bean
    public ApplicationContextFactory loadBatchDemoConfig(){
        return new GenericApplicationContextFactory(BatchDemoConfig.class);
    }


    @Bean
    public ApplicationContextFactory loadJobListenerConfig(){
        return new GenericApplicationContextFactory(JobListenerConfig.class);
    }
}
